<?php
/*
 * 手机客户端 拍卖信息处理函数
 * 2014-06-03
 */
 
 
 //加价幅度
function addpfunc($jg){
	if ($jg < 50){
		$addp = 1;
	}else if($jg >= 50 and $jg < 100){
		$addp = 5;
	}
	else if($jg >= 100 and $jg < 500){
		$addp = 10;
	}
	else if($jg >= 500 and $jg < 1000){
		$addp = 20;
	}
	else if($jg >= 1000 and $jg < 2000){
		$addp = 50;
	}
	else if($jg >= 2000 and $jg < 5000){
		$addp = 100;
	}
	else if($jg >= 5000 and $jg < 10000){
		$addp = 200;
	}
	else if($jg >= 10000 and $jg < 20000){
		$addp = 500;
	}
	else if($jg >= 20000 and $jg < 50000){
		$addp = 500;
	}
	else if($jg >= 50000 and $jg < 200000){
		$addp = 1000;
	}
	else {
		$addp = 2000;
	}
	return $addp;
}

// 出价 
function newbid($aid,$uid,$nick,$bid){
	setisbid0($aid);
	$db = $GLOBALS['db'];
	$db1 = $GLOBALS['db1'];
	$sql = "insert into auction_userbid(aid,uid,nick,bid,bid_dt) value('".$aid."','".$uid."','".$nick."','".$bid."',now())";
	$db->query($sql);
	$sql = "select aulbid from auction_userlastbid where aid = '".$aid."' and uid = '".$uid."'";
	$db->query($sql);
	if($db->next_record()){
		$sql1 = "UPDATE auction_userlastbid SET
					bid = '".$bid."',
					bid_dt = now(),
					is_bid = 1
				WHERE aid = '".$aid."' and uid = '".$uid."'";
		$db1->query($sql1);
	}else{
		$sql1 = "INSERT INTO auction_userlastbid(aid,uid,bid,bid_dt) VALUE('".$aid."','".$uid."','".$bid."',now())";
		$db1->query($sql1);
	}
	$sql = "update auction set lastprice = '".$bid."',bids = bids + 1,lasttime = now() WHERE aid = '".$aid."'";
	$db->query($sql);
	return $bid;
}
// 出价低于底价时 出价 
function newbid_1($aid,$uid,$nick,$bid){
	setisbid0($aid);
	$db = $GLOBALS['db'];
	$db1 = $GLOBALS['db1'];
	$sql = "insert into auction_userbid(aid,uid,nick,bid,bid_dt,is_bid) value('".$aid."','".$uid."','".$nick."','".$bid."',now(),0)";
	$db->query($sql);
	$sql = "select aulbid from auction_userlastbid where aid = '".$aid."' and uid = '".$uid."'";
	$db->query($sql);
	if($db->next_record()){
		$sql1 = "UPDATE auction_userlastbid SET
					bid = '".$bid."',
					bid_dt = now(),
					is_bid = 0
				WHERE aid = '".$aid."' and uid = '".$uid."'";
		$db1->query($sql1);
	}else{
		$sql1 = "INSERT INTO auction_userlastbid(aid,uid,bid,bid_dt,is_bid) VALUE('".$aid."','".$uid."','".$bid."',now(),0)";
		$db1->query($sql1);
	}
	$sql = "update auction set lastprice = '".$bid."',bids = bids + 1,lasttime = now() WHERE aid = '".$aid."'";
	$db->query($sql);
	return $bid;
}
//出代理价
function newbidproxy($aid,$uid,$bidproxy,$limittime){
	$db = $GLOBALS['db'];
	$sql = "delete from auction_userbidproxy where aid = '".$aid."'";
	$db->query($sql);
	$sql = "insert into auction_userbidproxy(aid,uid,bidproxy,bidproxy_dt,limittime) VALUE('".$aid."','".$uid."','".$bidproxy."',now(),'".$limittime."')";
	$db->query($sql);
	return $bidproxy;
}
//更新代理价
function modbidproxy($aid,$uid,$bidproxy,$limittime){
	$db = $GLOBALS['db'];
	$sql = "update auction_userbidproxy set
			uid = '".$uid."',
			bidproxy = '".$bidproxy."',
			limittime = '".$limittime."'
			WHERE aid = '".$aid."'";
	$db->query($sql);
	return $bidproxy;
}
//删除代理
function delproxy($aid){
	$db = $GLOBALS['db'];
	$sql = "delete from auction_userbidproxy where aid = '".$aid."'";
	$db->query($sql);
	return $bidproxy;
}
//旧出价无效
function setisbid0($aid){
	$db = $GLOBALS['db'];
	$sql = "update auction_userbid set is_bid = 0 where aid = '".$aid."' and is_bid = 1";
	$db->query($sql);
	$sql = "update auction_userlastbid set is_bid = 0 where aid = '".$aid."' and is_bid = 1";
	$db->query($sql);
}
//获取手机号
function getuidmobile($uid){
	$db = $GLOBALS['db'];
	$sql = "SELECT mobile FROM user_base WHERE uid = '".$uid."'";
	$db->query($sql);
	if($db->next_record()){
		$mobile = $db->f("mobile");
	}
	return $mobile;
}
//调用存储过程获取用户可用额度
function userCreditLimit($uid){
	$sql="call new_pro_get_user_ok_quota('".$uid."',@x)";
	$db = $GLOBALS['db'];
	$db->query($sql);
	$db->query("select @x");
	if($db->next_record()){
		return $db->f("@x");
	}
	return 0;
}
 ?>